/**
 * 	*****************************************************************************
 *				echarts插件域 闭包处理    作者：张鹏鹏   电话：15158822934
 *	*****************************************************************************
 */
(function($){
	
	var dataValuelineChart = [
	    	                  {
	    	                      name:'稻普1',
	    	                      type:'line',
	    	                      data:[11, 11, 15, 13, 12, 13, 10],
	    	                      markPoint : {
	    	                          data : [
	    	                              {type : 'max', name: '最大值'},
	    	                              {type : 'min', name: '最小值'}
	    	                          ]
	    	                      },
	    	                      markLine : {
	    	                          data : [
	    	                              {type : 'average', name: '平均值'}
	    	                          ]
	    	                      }
	    	                  },
	    	                  {
	    	                      name:'稻普2',
	    	                      type:'line',
	    	                      data:[1, -2, 2, 5, 3, 2, 0],
	    	                      markPoint : {
	    	                          data : [
	    	                              {name : '周最低', value : -2, xAxis: 1, yAxis: -1.5}
	    	                          ]
	    	                      },
	    	                      markLine : {
	    	                          data : [
	    	                              {type : 'average', name : '平均值'}
	    	                          ]
	    	                      }
	    	                  }
	    	              ];
	
	
	//折线图
	$.fn.lineChart = function(options){
		var defaluts = 
		{
			 "id":"echarts-line-chart",   //域id
			 "text":"稻普控股集团科技部",		  //标题
			 "categories":['稻普1','稻普2'], //分布类别
			 "formatter":"",   //刻度单位
			 "dataKey":['周一','周二','周三','周四','周五','周六','周日'],  //数据对应的key
			 "dataValue":dataValuelineChart  //需要的数据    json
		};
		var opts = $.extend(defaluts, options);
		var lineChart = echarts.init(document.getElementById(opts.id));
	    var lineoption = {
	        title : {
	            text: opts.text
	        },
	        tooltip : {
	            trigger: 'axis'
	        },
	        legend: {
	            data:opts.categories
	        },
	        grid:{
	            x:40,
	            x2:40,
	            y2:24
	        },
	        calculable : true,
	        xAxis : [
	            {
	                type : 'category',
	                boundaryGap : false,
	                data : opts.dataKey
	            }
	        ],
	        yAxis : [
	            {
	                type : 'value',
	                axisLabel : {
	                    formatter: '{value} '+opts.formatter
	                }
	            }
	        ],
	        series : opts.dataValue
	    };
	    lineChart.setOption(lineoption);
	    $(window).resize(lineChart.resize);
	};
	
	
	
	var dataValuebarChart =  [
	  	            {
		                name:'稻普1',
		                type:'bar',
		                data:[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3],
		                markPoint : {
		                    data : [
		                        {type : 'max', name: '最大值'},
		                        {type : 'min', name: '最小值'}
		                    ]
		                },
		                markLine : {
		                    data : [
		                        {type : 'average', name: '平均值'}
		                    ]
		                }
		            },
		            {
		                name:'稻普2',
		                type:'bar',
		                data:[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],
		                markPoint : {
		                    data : [
		                        {name : '年最高', value : 182.2, xAxis: 7, yAxis: 183, symbolSize:18},
		                        {name : '年最低', value : 2.3, xAxis: 11, yAxis: 3}
		                    ]
		                },
		                markLine : {
		                    data : [
		                        {type : 'average', name : '平均值'}
		                    ]
		                }
		            }
		        ];
	
	
	//柱状图
	$.fn.barChart = function(options){
		var defaluts = 
		{
			 "id":"echarts-bar-chart",   //域id
			 "text":"稻普控股集团科技部",		  //标题
			 "categories":['稻普1','稻普2'], //分布类别
			 "formatter":"",   //刻度单位
			 "dataKey":['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],  //数据对应的key
			 "dataValue":dataValuebarChart  //需要的数据    json
		};
		var opts = $.extend(defaluts, options);
		
		var barChart = echarts.init(document.getElementById(opts.id));
	    var baroption = {
	        title : {
	            text: opts.text
	        },
	        tooltip : {
	            trigger: 'axis'
	        },
	        legend: {
	            data:opts.categories
	        },
	        grid:{
	            x:30,
	            x2:40,
	            y2:24
	        },
	        calculable : true,
	        xAxis : [
	            {
	                type : 'category',
	                data : opts.dataKey
	            }
	        ],
	        yAxis : [
	            {
	                type : 'value', 
                	axisLabel : {
	                    formatter: '{value} '+opts.formatter
	                }
	            }
	        ],
	        series :opts.dataValue
	    };
	    barChart.setOption(baroption);

	    window.onresize = barChart.resize;	
	};
	
	
	var dataValuepieChart =  [
		          	            {
		        	                name:'稻普集团',
		        	                type:'pie',
		        	                radius : '55%',
		        	                center: ['50%', '60%'],
		        	                data:[
		        	                    {value:335, name:'稻普1'},
		        	                    {value:310, name:'稻普2'},
		        	                    {value:234, name:'稻普3'},
		        	                    {value:135, name:'稻普4'},
		        	                    {value:1548, name:'稻普5'}
		        	                ]
		        	            }
	        	        ];
	
	//柱状图
	$.fn.pieChart = function(options){
		var defaluts = 
		{
			 "id":"echarts-pie-chart",   //域id
			 "text":"稻普控股集团科技部",		  //标题
			 "subtext":"稻普科技部",   		 //二级菜单
			 "formatter":"{a} <br/>{b} : {c} ({d}%)",  //鼠标悬浮表达式
			 "categories":['稻普1','稻普2','稻普3','稻普4','稻普5'], //分布类别
			 "dataValue":dataValuepieChart,  //需要的数据    json
			 "legendx":"left", //类别名称的方向[left,right]
		};
		var opts = $.extend(defaluts, options);
	    var pieChart = echarts.init(document.getElementById(opts.id));
	    var pieoption = {
	        title : {
	            text: opts.text,
	            subtext: opts.subtext,
	            x:'center'
	        },
	        tooltip : {
	            trigger: 'item',
	            formatter: opts.formatter
	        },
	        legend: {
	            orient : 'vertical',
	            x : opts.legendx,
	            data:opts.categories
	        },
	        calculable : true,
	        series : opts.dataValue
	    };
	    pieChart.setOption(pieoption);
	    $(window).resize(pieChart.resize);
	};
	
	
	var dataValueradarChart =  [
	            	            {
	            	                name: '产品   vs 开发',
	            	                type: 'radar',
	            	                data : [
	            	                    {
	            	                        value : [4300, 10000, 28000, 35000, 50000, 19000],
	            	                        name : '产品分配'
	            	                    },
	            	                     {
	            	                        value : [5000, 14000, 28000, 31000, 42000, 21000],
	            	                        name : '开发分配'
	            	                    }
	            	                ]
	            	            }
	            	        ];
	
	var dataKey = [
                   { text: '稻普1', max: 6000},
                   { text: '稻普2', max: 16000},
                   { text: '稻普3', max: 30000},
                   { text: '稻普4', max: 38000},
                   { text: '稻普5', max: 52000},
                   { text: '稻普6', max: 25000}
                ];
	
	//雷达图
	$.fn.radarChart = function(options){
		var defaluts = 
		{
			 "id":"echarts-radar-chart",   //域id
			 "text":"稻普控股集团科技部",		  //标题
			 "subtext":"稻普科技部",   		 //二级菜单
			 "categories":['产品分配','开发分配'], //分布类别
			 "dataKey":dataKey,  //数据对应的key
			 "dataValue":dataValueradarChart,  //需要的数据    json
			 "legendx":"right", //类别名称的方向[left,right]
		};
		var opts = $.extend(defaluts, options);
	    var radarChart = echarts.init(document.getElementById(opts.id));
	    var radaroption = {
	        title : {
	            text: opts.text,
	            subtext: opts.subtext
	        },
	        tooltip : {
	            trigger: 'axis'
	        },
	        legend: {
	            orient : 'vertical',
	            x : opts.legendx,
	            y : 'bottom',
	            data:opts.categories
	        },
	        polar : [
	           {
	               indicator : opts.dataKey
	            }
	        ],
	        calculable : true,
	        series :opts.dataValue
	    };

	    radarChart.setOption(radaroption);
	    $(window).resize(radarChart.resize);
	};
})(jQuery);